//
//  ViewController.m
//  webView
//
//  Created by 黄礼潮 on 16/2/17.
//  Copyright © 2016年 黄礼潮. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@property(nonatomic,strong) UIWebView * webView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    self.webView = [[UIWebView alloc]init];
    self.webView.frame = self.view.bounds;
    
    [self.view addSubview:self.webView];
    
    NSURL *url = [NSURL URLWithString:@"http://m.baidu.com"];
    
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    
    

    [request setValue:@"iPhone" forHTTPHeaderField:@"User-Agent"];
    
    [[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        
        //用NSData --->HTML字符串
        NSString *html = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
        //用webView加载html
        
        // baseURL  是加载素材的路径
        [self.webView loadHTMLString:html baseURL:url];
        
        
    }]resume];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
